
;		MAIN.A86
;
;Main line routines for MODEM9.xx.
;
START:
	MOV	AX,SS
	MOV	SAVESS,AX
	MOV	AX,SP
	MOV	SAVESP,AX
	PUSHF
	POP	BX
	MOV	AX,DS
	MOV	SS,AX
	MOV	SP,STACKTOP
	PUSH	BX
	POPF
	CLD
	CALL	INITADR		;INITIALIZE ADDRESSES
	CALL	VERNUM		;GIVE CONFIGURATION MESSAGE
	CALL	GETUSR		;GET USER
	MOV	SAVUSR,AL	;SAVE FOR EXIT
	MOV	NFILFLG,TRUE
	MOV	SAVEFLG,FALSE
	CALL	PROCOPT		;PROCESS CONTROL OPTIONS
;
RESTART:
	MOV	AL,OPTION	;GET MAIN OPTION
	CMP	AL,' '		;NO OPTION SPEC'D?
	JZ	MENUJMP		;TRUE, GO MENU
	CMP	AL,'H'		;MENU ASKED FOR?
	JZ	MENU2JMP	;YES, GO MENU2
	CALL	INITMOD
	CALL	MOVEFCB
	CALL	INMODDATP 	;GOBBLE UP GARBAGE..
	CALL	INMODDATP 	;..CHARACTERS ON LINE
	MOV	ECHOFLG,0	; RESET ECHO FLAG
	MOV	LOCFLG,0	; RESET LOCAL FLAG
	MOV	AL,OPTION	;PROCESS MAIN OPTION
	CMP	AL,'E'		;ECHO MODE?
	JNZ	NOECH		;JUMP IF NOT
	MOV	ECHOFLG,TRUE	;SET ECHO TO TRUE
	JMP	DSKSAVE
;
MENU2JMP:
	JMP	MENU2
;
NOECH:	CMP	AL,'L'		;LOCAL ECHO MODE
	JNZ	NOLOC
	MOV	AL,TRUE
	MOV	LOCFLG,AL
	JMP	DSKSAVE

NOLOC:
	CMP	AL,'T'		;TERMINAL MODE?
	JNZ	NOLOC1
	JMP	DSKSAVE		;YES

NOLOC1:
	CMP	AL,'S'		;SEND A FILE?
	JNZ	NOLOC2
	JMP	SENDFIL		;YES

NOLOC2:
	CMP	AL,'R'		;RECEIVE A FILE?
	JNZ	NOLOC3
	JMP	RCVFIL		;YES

NOLOC3:
	CALL	NOTVLDMSG	;SAY NOT A VALID OPTION
MENUJMP:
	JMP	MENU		;NO VALID OPTION SPEC'D, GO MENU
;
INITADR:
	JMP	INITMOD		;RETURN DONE FROM THIS ROUTINE..
;
; CHECK OPTIONS, PUT 0 IN APPROPRIATE PLACES IN OPTION TABLE
; IF OPTION SELECTED
;
PROCOPT:
	MOV	DX,OFFSET FCB+1
	XCHG	BX,DX
	MOV	AL,BYTE PTR [BX]
	XCHG	BX,DX
	MOV	OPTION,AL
OPTLP:
	INC	DX
	XCHG	BX,DX
	MOV	AL,BYTE PTR [BX]
	XCHG	BX,DX
	CMP	AL,' '
	JZ	ENDOPT
	MOV	BX,OFFSET OPTBL
	MOV	CH,OFFSET OPTBE- OFFSET OPTBL
OPTCK:
	CMP	AL,BYTE PTR [BX]
	JNZ	OPTNO
	CMP	AL,'B'
	JNZ	OPTCK1
	MOV	AL,OPTION
	CMP	AL,'S'
	JZ	OPTCK1
	CMP	AL,'R'
	JNZ	OPTNO1
OPTCK1:
	MOV	BYTE PTR [BX],0
	JMP	OPTLP
;
OPTNO:
	INC	BX
	DEC	CH
	JNZ	OPTCK
OPTNO1:
	CALL	NOTVLDMSG
	POP	AX		;PRESERVE STACK
	JMP	MENU
;
ENDOPT:
	MOV	AL,VSEEFLG
	OR	AL,AL
	JNZ	ENDOPTRT
	MOV	QFLG,AL		;IF VIEWING SUPPRESS ALL ELSE
ENDOPTRT:
	RET
;
MOVEFCB:
	MOV	BX,OFFSET FCB+16
	MOV	DX,OFFSET FCB
	MOV	CH,16
	CALL	MOVE
	MOV	BYTE PTR .FCBSNO,0
	MOV	BYTE PTR .FCBEXT,0
	RET
;
;
PRTMSG:
	MOV	CL,PRINT
	INT	224
	RET
;
EXIT:
	MOV	DL,SAVUSR
	CALL	SETUSR
	MOV	DX,OFFSET 80H
	MOV	CL,STDMA
	INT	224
	CALL	CKMODM		;CATCH ANY GARBAGE CHARACTERS (is this safe?)
COLDBOOT:
	PUSHF			;Must keep the flags in a register
	POP	BX		; as the current stack is about to blow
	MOV	AX,SAVESS	;Restore the original stack segment
	MOV	SS,AX
	MOV	AX,SAVESP	; and pointer
	MOV	SP,AX
	PUSH	BX
	POPF			;Restore the flags
	MOV	CX,0		;Exit is via BDOS call 0
	MOV	DX,0
	INT	224		;We're off to see the wizard....
;
;INITIALIZES CP/M FILE CONTROL BLOCKS AT 5CH AND 6CH
;
SETFCB:
	MOV	DX,OFFSET CMDBUF
	MOV	BX,OFFSET FCB
	CALL	CPMLINE
	CALL	PROCOPT
CHECKNM:
	MOV	AL,BYTE PTR .FCB+1	;CHECK ON THE PRIMARY OPTION
	CMP	AL,'E'		;RETURN IF ECHO OPTION
	JZ	CHECKNMRT
	CMP	AL,'H'		;RETURN IF HELP OPTION
	JZ	CHECKNMRT
	CMP	AL,'L'		;RETURN IF LOCAL ECHO OPTION
	JZ	CHECKNMRT
	CMP	AL,'T'
	JNZ	L@103
	JMP	TERMSEL
L@103:
	CMP	AL,'S'
	JNZ	L@104
	JMP	CKFILE
L@104:
	CMP	AL,'R'
	JNZ	BDOPT
	MOV	AL,BATCHFLG 	;IF MULT FILE MODE, THEN..
	OR	AL,AL		 ;..RECV OPT DOES NOT NEED..
	JNZ	CKFILE
CHECKNMRT:
	RET
;
BDOPT:
	CALL	ILPRT
	DB	CR,LF,'++ Bad Option ++',CR,LF,0
	JMP	REENT

CKFILE:
	MOV	AL,BYTE PTR .FCB+17	;IF OPTION THAT NEEDS FILE NAME,..
	CMP	AL,' '		;..THEN CHECK TO SEE IF NAME..
	JNZ	CHECKNMRT	;...EXISTS. IF NOT..
REENT:
	CALL	ILPRT		;..DO EVERYTHING OVER.
	DB	CR,LF,'Re-enter PRIMARY option and file name only: ',BELL,0
	MOV	DX,OFFSET CMDBUF
	CALL	INBUFF
	JMP	SETFCB
;
TERMSEL:
	CMP	BYTE PTR .FCB+17,' '
	JNZ	SAVAGN
	MOV	SAVEFLG,FALSE
	MOV	NFILFLG,TRUE
	RET
;
SAVAGN:
	MOV	NFILFLG,FALSE
	RET
;
;
;ADJUSTS LOOP COUNTERS FOR VARIOUS CLOCK SPEEDS
;
FIXCNT:
	MOV	AL,CLOCK
	CMP	AL,1
	JZ	FIXCNTRT
	PUSH	DX
	PUSH	BX
	POP	DX
CNTMUL:
	ADD	BX,DX
	DEC	AL
	JNZ	CNTMUL
	POP	DX
FIXCNTRT:
	RET
;
MOVE128:
	MOV	CH,128
MOVE:
	MOV	SI,BX
	PUSH	DS
	POP	ES
	MOV	DI,DX
MOVE001:
	MOVS	BYTE PTR [DI], BYTE PTR [SI]
	DEC	CH
	JNZ	MOVE001
	MOV	BX,SI
	MOV	DX,DI
	RET
;
MENU0:
	TEST	NFILFLG,0FFH
	JZ	MENU1
	JMP	MENU		;GO IF NO FILE ACTIVE

MENU1:
	CALL	ILPRT		;ELSE PRINT MESSAGE
	DB	CR,LF,LF
	DB	'** There may be text in the memory buffer **',CR,LF
	DB	'** It will be lost unless NOL or WRT commands are used **'
	DB	CR,LF,BELL,0
	MOV	CH,2		;2 MORE BELLS
BLOOP:
	MOV	AL,BELRPT	;GET TIME
	MOV	CL,AL
BCLOOP:
	MOV	BX, 1000	;ABOUT 0.03 SECONDS
	CALL	FIXCNT
BILOOP:
	MOV	AL,BL
	OR	AL,BH
	DEC	BX
	JNZ	BILOOP
	DEC	CL
	JNZ	BCLOOP
	MOV	AL,BELL
	CALL	TIPE
	DEC	CH
	JNZ	BLOOP
;
MENU:
	MOV	BX,OFFSET RESTSN  ;RESTORE SECTOR NUMBERS..
	MOV	DX,OFFSET SECTNOB ;..FOR NEW FILE TRANSFER.
	MOV	CH,OFFSET SECTNOE- OFFSET SECTNOB
	CALL	MOVE
	MOV	BX,OFFSET RESTROPT ;RESTORE OPTION TABLE
	MOV	DX,OFFSET OPTBL
	MOV	CH,OFFSET OPTBE- OFFSET OPTBL
	CALL	MOVE
	MOV	AL,0
	MOV	MFFLG1,AL	;RESET MFACCESS ROUTINE..
	NOT	AL		;..AND MULTI TRANS IN CASE..
	MOV	FSTFLG,AL	;..OF ABORT.
	JMP	XPRT
;
MENU2:
	CALL	CLRTST
	CALL    ILPRT
	DB	'               Single Letter Commands',CR,LF,LF
	DB	' H  - Display this information',CR,LF
	DB	' ?  - Display current settings',CR,LF,LF
	DB      ' T  - Terminal mode',CR,LF
	DB      ' E  - Terminal mode with echo',CR,LF
	DB	' L  - Terminal mode with local echo',CR,LF
	DB	'     For capturing text use T(or E or L) FILENAME.TYP and'
	DB	CR,LF
	DB	'     Start & Stop toggles described on subsequent screen.'
	DB	CR,LF,LF
	DB      ' R  - Receive CP/M file using Christensen Protocol',CR,LF
	DB      ' S  - Send CP/M file using Christensen Protocol',CR,LF
	DB	'     Command is: R(or S) FILENAME.TYP',CR,LF
	DB	'     R and S can use the following subcommands:',CR,LF
	DB	'          B  - Bulk transfer using wildcards (e.g. *.*)',CR,LF
	DB	'          Q  - Quiet mode (no messages to console)',CR,LF
	DB	'          T  - Return to terminal mode after transfer',CR,LF
	DB	'          V  - View bytes transferred on console',CR,LF,LF
	DB	'The single letter commands may also be used on the',CR,LF
	DB	'command line when the program is initially executed.'
	DB	CR,LF,LF,0
;
	CALL	NXTSCRN
;
	CALL	ILPRT
	DB	'               Three Letter Commands',CR,LF,LF
	DB      'CPM - Exit from this program to CP/M',CR,LF
	DB      'DIR - List directory and space free (may specify drive)'
	DB	CR,LF
	DB	'ERA - Erase file (may specify drive)',CR,LF
	DB	'LOG - Change default drive/user (specify drive/user)'
	DB	CR,LF
	DB	'      and reset disks.  e.g. LOG A0, LOG B (user unchanged)'
	DB	CR,LF
	DB	'FOP - Display commands for setting terminal mode file',CR,LF
	DB	'      output parameters',CR,LF,0
;
	TEST	DISCFLG,0FFH
	JZ	NODISC
	CALL	ILPRT
	DB	'DSC - Disconnect the modem from the telephone line',CR,LF,0
;
NODISC:
	TEST	SETUPTST,0FFH
	JNZ	NOTIME
	CALL	ILPRT
	DB	'TIM - Set S mode time-to-send message',CR,LF,0
;
NOTIME:
	MOV	AL,TOGGLECRC
	OR	AL,AL
	JZ	NOTOGCRC
	CALL	ILPRT
	DB	'TCC - Toggle Checksum/CRC mode on receive',CR,LF,0
;
NOTOGCRC:
	TEST	TOGGLEBK,0FFH
	JZ	NOTOGBK
	CALL	ILPRT
	DB	'TBR - Toggle backspace to rub conversion',CR,LF,0
;
NOTOGBK:
	TEST	TOGGLELOC,0FFH
	JZ	NOTOGLOC
	CALL	ILPRT
	DB	'TLC - Toggle  1) local command immediate',CR,LF
	DB	'              2) local command after ',0
	MOV	AL,EXTCHR
	CALL	SHFTYPE
	DB	CR,LF,0
;
NOTOGLOC:
	MOV	AL,TOGGLELF
	OR	AL,AL
	JZ	NOTOGLF
	CALL	ILPRT
	DB	'TLF - Toggle send linefeed after carriage return',CR,LF,0
;
NOTOGLF:
	CALL	ILPRT
	DB	'NUM - List remote systems',CR,LF,0
	MOV	AL,SETUPTST
	OR	AL,AL
	JZ	NOSETUP
	CALL	ILPRT
	DB	'SET - Set communication ports',CR,LF,0
;
NOSETUP:
	MOV	AL,LF
	CALL	TIPE
	CALL	ILPRT
	DB	'    The following are terminal text buffer commands:'
	DB	CR,LF,0
	CALL	ILPRT
	DB      'DEL - Delete memory buffer and file',CR,LF
	DB      'NOL - Return to terminal mode - no loss of data in buffer'
	DB	CR,LF
	DB      'WRT - Write memory buffer to disk file',CR,LF,LF,0
	CALL	NXTSCRN
;
	CALL	ILPRT
	DB	'      Local Commands while in Terminal Mode',CR,LF,LF,0
	MOV	AL,EXITCHR
	CALL	SHFTYPE
	DB	'  - Exit to command mode',CR,LF,LF,0
	MOV	AL,TRANLOGON
	OR	AL,AL
	JZ	NOTRANLOG
	MOV	AL,LOGCHR
	CALL	SHFTYPE
	DB	'  - Transmit string',CR,LF
	DB	'     Must be followed by number of string (0-9)',CR,LF
	DB	'     or L to display list of strings',CR,LF,LF,0
;
NOTRANLOG:
	TEST	LSTTST,0FFH
	JZ	NOLST2
	MOV	AL,LSTCHR
	CALL	SHFTYPE
	DB	'  - Toggle printer',CR,LF,0
;
NOLST2:
	MOV	AL,LF
	CALL	TIPE
	MOV	AL,SAVECHR
	CALL	SHFTYPE
	DB	'  - Start copy into buffer',CR,LF,0
	MOV	AL,UNSAVECHR
	CALL	SHFTYPE
	DB      '  - Stop copy into buffer',CR,LF
	DB	'     Start & Stop may be toggled as often as desired.',CR,LF
	DB	'     A ":" at start of line indicates buffer is open.',CR,LF
	DB	'     XOFF automatically used to stop input when writing',CR,LF
	DB	'     full buffer to disk, XON sent to resume.',CR,LF,LF,0
	MOV	AL,TRANCHR
	CALL	SHFTYPE
	DB	'  - Transfer ASCII file to remote',CR,LF,LF,0
	MOV	AL,LOCONEXTCHR
	OR	AL,AL
	MOV	AL,EXTCHR
	JNZ	REMDFLT
	CALL	SHFTYPE
	DB	'  - Send local control character to remote',CR,LF,0
	JMP	XPRT
REMDFLT:
	CALL	SHFTYPE
	DB	'  - Next character will be used for local control',CR,LF,0
;
XPRT:
	CALL	ILPRT
	DB	CR,LF,'Drive ',0
	MOV	CL,CURDSK	;CURRENT DISK FUNCTION
	INT	224
	ADD	AL,'A'		;MAKE ASCII
	CALL	TIPE
;
	CALL	GETUSR		;GET CURRENT USER NUMBER
	CMP	AL,0
	JZ	SR3B		;SKIP IF USER 0
	PUSH	AX
	CALL	ILPRT
	DB	', User ',0
	POP	AX
	MOV	BH,0
	MOV	BL,AL
	CALL	DECOUT		;REPORT USER
;
SR3B:
	CALL	CRLF
	TEST	NFILFLG,0FFH
	JNZ	NOBUFMSG
	CALL	GETSPC
	CALL	ILPRT
	DB	' bytes of buffer free',CR,LF,0
NOBUFMSG:	
	CALL	ILPRT
	DB	'COMMAND (H for Help): ',0
GETCMD:
	MOV	DX,OFFSET CMDBUF	;ENTER COMMAND
	CALL	INBUFF
	CALL	CRLF
	MOV	DX,OFFSET CMDBUF+2 ;POINT TO COMMAND
	CALL	ILCOMP
	DB	'CPM',0
	JC	GETCMD1
	JMP	EXIT

GETCMD1:
	CALL	ILCOMP
	DB	'LOG',0
	JC	GETCMD2
	JMP	LOGNEW

GETCMD2:
	CALL	ILCOMP
	DB	'DIR',0
	JC	GETCMD3
	JMP	DIR

GETCMD3:
	CALL	ILCOMP
	DB	'ERA',0
	JC	GETCMD4
	JMP	ERASEF

GETCMD4:
	CALL	ILCOMP
	DB	'DSC',0
	JC	GETCMD5
	JMP	DISC

GETCMD5:
	CALL	ILCOMP
	DB	'?',0
	JC	GETCMD6
	JMP	CURPAR

GETCMD6:
	CALL	ILCOMP
	DB	'SPD',0
	JC	GETCMD7
	JMP	SETSPD

GETCMD7:
	CALL	ILCOMP
	DB	'FOP',0
	JC	GETCMD8
	JMP	TFOMENU

GETCMD8:
	CALL	ILCOMP
	DB	'TIM',0
	JC	GETCMD9
	JMP	SETTIM

GETCMD9:
	CALL	ILCOMP
	DB	'TCC',0
	JC	GETCMD10
	JMP	TOGCRC

GETCMD10:
	CALL	ILCOMP
	DB	'TBR',0
	JC	GETCMD11
	JMP	TOGBKSP

GETCMD11:
	CALL	ILCOMP
	DB	'TLC',0
	JC	GETCMD12
	JMP	TOGLOC

GETCMD12:
	CALL	ILCOMP
	DB	'TLF',0
	JC	GETCMD13
	JMP	TOGLF

GETCMD13:
	CALL	ILCOMP
	DB	'TSL',0
	JC	GETCMD14
	JMP	TOGSTL

GETCMD14:
	CALL	ILCOMP
	DB	'TXF',0
	JC	GETCMD15
	JMP	TOGTXOFF

GETCMD15:
	CALL	ILCOMP
	DB	'TXN',0
	JC	GETCMD16
	JMP	TOGTXON

GETCMD16:
	CALL	ILCOMP
	DB	'TWE',0
	JC	GETCMD17
	JMP	TOGWECH

GETCMD17:
	CALL	ILCOMP
	DB	'TEF',0
	JC	GETCMD18
	JMP	TOGTEOF

GETCMD18:
	CALL	ILCOMP
	DB	'NUM',0
	JC	GETCMD19
	JMP	NUMPRN

GETCMD19:
	MOV	AL,SETUPTST
	OR	AL,AL
	JZ	NOSETUP2
	CALL	ILCOMP
	DB	'SET',0
	JC	NOSETUP2
	JMP	SETUPENT

NOSETUP2:
	CALL	ILCOMP
	DB	'NOL',0
	JC	NXTOPT1		;CARRY SET = NO MATCH
	MOV	AL,NFILFLG
	OR	AL,AL
	JZ	NOSETUP3
	JMP	NOFILOPN	;GO TELL OPERATOR IF NO FILE OPEN

NOSETUP3:
	CALL	BUFMSG
	MOV	BX,HLSAVE	;RETURN TO TERMINAL..
	JMP	TERM		;..MODE WITH SAVE OPTION..
				;..IF PREVIOUSLY ENABLED.
;
NXTOPT1:
	CALL	ILCOMP
	DB	'WRT',0
	JC	NXTOPT2
	JMP	WRTFIL

NXTOPT2:
	CALL	ILCOMP
	DB	'DEL',0
	JC	NXTOPT3
	JMP	NEWFILE

NXTOPT3:
	PUSH	BX
	MOV	AL,CMDBUF+2
	MOV	BX,OFFSET COMPLIST
	CALL	COMPARE		;COMPARES LIST POINTED TO BY HL..
	POP	BX		;..TO CHAR IN A-REG.
	JC	NOTVLD		;CARRY SET = NO MATCH
DOOPT:
	PUSH	BX		;LOAD ORIGINAL FCB WITH TRANSFER..
	CALL	SETFCB		;..CMDS AND GO TO BEGINNING OF..
	POP	BX		;..PROGRAM. WILL FOLLOW SAME LOGIC..
	JMP	RESTART		;..AS IF PROGRAM WERE CALLED WITH..
				;..CP/M COMMAND LINE.
;
NOTVLD:
	CALL	NOTVLDMSG
	JMP	XPRT
;
NOTVLDMSG:
	CALL	ILPRT
	DB	'++ Invalid Command ++',CR,LF,BELL,0
	RET
;
DIR:
	MOV	CL,CURDSK
	INT	224
	MOV	DISKSAV,AL
	CALL	DIRLST
	MOV	DL,DISKSAV
	MOV	CL,SELDSK
	INT	224
	JMP	XPRT
;
LOGNEW:
	TEST	NFILFLG,0FFH
	JNZ	LOGNEW1
	JMP	NORESET

LOGNEW1:
	MOV	AL,CMDBUF+6
	CMP	AL,' '
	JNZ	SPECIFD
	MOV	CL,CURDSK
	INT	224
	ADD	AL,'A'
SPECIFD:
	SUB	AL,'A'
	MOV	DISKSAV,AL
	CMP	AL,16
	JC	SPECIFD1
	JMP	NOTVLD

SPECIFD1:
	MOV	AL,CMDBUF+7	;GET NEW USER NUMBER
	CMP	AL,' '		;CHECK FOR SPACE
	JZ	SR7A		;EXIT IF NO NEW USER NUMBER SPECIFIED
	CALL	NUMCHK		;CHECK TO SEE IF IT IS A NUMBER
	MOV	CH,AL		;SAVE
	MOV	AL,CMDBUF+8	;GET SECOND DIGIT
	CMP	AL,' '
	JZ	SR7B		;GO IF SPACE
	CALL	NUMCHK
	MOV	CL,AL		;SAVE
	MOV	AL,CH		;GET SAVED FIRST DIGIT
	ADD	AL,AL		; X2
	ADD	AL,AL		; X4
	ADD	AL,AL		; X8
	ADD	AL,CH		; X9
	ADD	AL,CH		; X10
	ADD	AL,CL
	CMP	AL,16		;CHECK FOR < 16
	JC	SPECIFD2
	JMP	NOTVLD		;GO IF NOT

SPECIFD2:
	MOV	CH,AL
SR7B:
	PUSH	CX
	CALL	GETUSR
	POP	CX		;RESTORE SELECTED USER
	CMP	AL,CH		;AND COMPARE THEM
	JZ	SR7A		;EXIT IF UNCHANGED
	MOV	DL,CH		;ELSE SET NEW USER
	CALL	SETUSR
;
SR7A:
	CALL	ILPRT
	DB	'Insert disk for drive ',0
	MOV	AL,DISKSAV
	ADD	AL,'A'
	CALL	TIPE
NOTCR:
	CALL	ILPRT
	DB	CR,LF,'Hit return when ready',0
	CALL	KEYIN
	CMP	AL,CR
	JNZ	NOTCR
	CALL	CRLF
	MOV	CL,RESET
	INT	224	
	MOV	DL,DISKSAV
	MOV	CL,SELDSK
	INT	224
	JMP	XPRT
;
GETUSR:
	MOV	DL,0FFH		;GET CURRENT USER
SETUSR:
	MOV	CL,USER		;SET-UP FUNCTION CALL
	INT	224		;NUMBER IN RETURNED IN A
	RET
;
NORESET:
	CALL	ILPRT
	DB	'++      Terminal mode file open      ++',CR,LF
	DB	'++ Use WRT or DEL before LOG command ++',CR,LF
	DB	CR,LF,LF,BELL,0
	XOR	AL,AL
	JMP	XPRT
;
ERASEF:
	MOV	DX,OFFSET CMDBUF ;PUT CMD LINE INTO FCB AT HL
	MOV	BX,OFFSET FCB
	CALL	CPMLINE
	CALL	MOVEFCB		;MOVE FCB+16 TO FCB
	CMP	BYTE PTR .FCB+1,' '
	JNZ 	ERASEF1
	JMP	NOTVLD		;GO IF NO FILE SPECIFIED

ERASEF1:
	MOV	DX,OFFSET FCB
	MOV	CL,SRCHF
	INT	224
	INC	AL		;0 IF FILE NOT FOUND
	JNZ	ERAFILE 	;OK, GO ERASE
	CALL	ILPRT
	DB	'++ File not found ++',CR,LF,BELL,0
	JMP	XPRT
;
ERAFILE:
	MOV	DX,OFFSET FCB
	MOV	CL,ERASE
	INT	224
	CALL	ILPRT
	DB	'File erased',CR,LF,0
	JMP	XPRT
;
DISC:
	MOV	AL,DISCFLG
	OR	AL,AL
	JNZ	DISC1
	JMP	NOTVLD

DISC1:
	CALL	DISCR
	CALL	ILPRT
	DB	'** Disconnected **',CR,LF,BELL,0
	JMP	XPRT
;
SETSPD:
	CALL	ILPRT
	DB	'Enter character output delay [0(none) - 9(longest delay)]: ',0
	CALL	NUMGET
	JNC	NOCHG1
	MOV	BYTDLY,AL
NOCHG1:
	CALL	SPDMSG
	CALL	ILPRT
	DB	CR,LF,'Enter additional delay after <CR> [0-9]: ',0
	CALL	NUMGET
	JNC	NOCHG2
	ROL	AL,1		;X2
	ROL	AL,1		;X4
	MOV	CRDLY,AL
NOCHG2:
	CALL	CRDLYMSG
	JMP	XPRT
;
NUMGET:
	MOV	DX,OFFSET CMDBUF
	CALL	INBUFF
	MOV	AL,CMDBUF+2 	;GET NUMBER
	CMP	AL,' '
	JZ	NUMCHKRT
NUMCHK:
	SUB	AL,'0'
	CMP	AL,10
	JC	NUMCHKRT
	POP	AX		;PRESERVE STACK
	JMP	NOTVLD

NUMCHKRT:
	RET
;
SPDMSG:
	CALL	ILPRT
	DB	'Terminal mode file output delay is 0.',0
	MOV	AL,BYTDLY
	CALL	GIVNUM
	CALL	ILPRT
	DB	' seconds per character',CR,LF,0
	RET
;
CRDLYMSG:
	CALL	ILPRT
	DB	'Additional delay after <CR> is 0.',0
	MOV	AL,CRDLY
	CALL	GIVNUM
	CALL	ILPRT
	DB	' seconds',CR,LF,0
	RET
;
GIVNUM:
	ADD	AL,AL		;2X
	CMP	AL,10
	MOV	CH,AL
	JNC	NOZERO
	MOV	AL,'0'
	CALL	TIPE
	MOV	AL,CH
NOZERO:
	PUSH	BX
	MOV	BL,AL
	MOV	BH,0
	CALL	DECOUT
	POP	BX
	RET
;
SETTIM:
	MOV	AL,SETUPTST
	OR	AL,AL
	JZ	SETTIM1
	JMP	NOTVLD

SETTIM1:
	CALL	ILPRT
	DB	'Use 0-7 to give baud rate for S mode time-to-send message,'
	DB	CR,LF
	DB	'where 0=110, 1=300, 2=600, 3=1200, 4=2400',CR,LF
	DB	'5=4800, 6=9600 and 7 = 19200 baud',CR,LF,LF,'Enter value: ',0
	CALL	NUMGET
	CMP	AL,8
	JC	SETTIM1A
	JMP	NOTVLD

SETTIM1A:
	MOV	MSPEED,AL
	CALL	SETTIM2
	JMP	XPRT
;
SETTIM2:
	MOV	AL,SETUPTST
	OR	AL,AL
	JNZ	SETTIM3
	CALL	ILPRT
	DB	'Rate for the S mode time-to-send message is set to ',0
	JMP	SETTIM4

SETTIM3:
	CALL	ILPRT
	DB	'Modem speed is ',0
SETTIM4:
	CALL	BAUDPRT
	RET
;
;Shows baud rates set for 'time to send' file transfer.
;
BAUDPRT:
	MOV	BX,OFFSET BAUDSPD
	MOV	DH,0
	MOV	AL,MSPEED	;GET BAUD RATE CODE
	ADD	AL,AL		;X2
	MOV	DL,AL
	ADD	BX,DX		;POINT TO CORRECT RATE
	MOV	AL,BYTE PTR [BX] ; GET FIRST DIGIT
	CALL	TIPE
	INC	BX
	MOV	AL,BYTE PTR [BX] ; GET SECOND DIGIT
	CALL	TIPE
	MOV	AL,MSPEED
	CMP	AL,7
	JC	NOTFAST
	INC	BX
	MOV	AL,Byte Ptr [BX] ;Get third digit
	CALL	TIPE
NOTFAST:
	MOV	AL,MSPEED	;CHECK FOR GREATER THAN 1000
	CMP	AL,3
	JC	NOTHOU		;GO IF LESS
	MOV	AL,'0'		;PRINT EXTRA 0
	CALL	TIPE
NOTHOU:
	CALL	ILPRT
	DB	'0 baud',CR,LF,0
	RET
;
BAUDSPD	DB	'11','30','60','12','24','48','96','192'
;
TOGCRC:
	MOV	AL,TOGGLECRC
	OR	AL,AL
	JNZ	TOGCRC1
	JMP	NOTVLD
TOGCRC1:
	MOV	AL,CKSUMDFLT
	NOT	AL
	MOV	CKSUMDFLT,AL
	CALL	TOGCRC2
	JMP	XPRT
;
TOGCRC2:
	OR	AL,AL
	JNZ	CHEKMSG
	CALL	ILPRT
	DB	'CRC mode set',CR,LF,0
	RET
;
CHEKMSG:
	CALL	ILPRT
	DB	'Checksum mode set',CR,LF,0
	RET
;
TOGBKSP:
	MOV	AL,TOGGLEBK
	OR	AL,AL
	JNZ	TEMP8
	JMP	NOTVLD
TEMP8:
	MOV	AL,CONVBKSP
	NOT	AL
	MOV	CONVBKSP,AL
	CALL	TOGBKSP2
	JMP	XPRT
;
TOGBKSP2:
	TEST	CONVBKSP,0FFH
	JZ	NORUBMSG
	CALL	ILPRT
	DB	'Backspace is rub',CR,LF,0
	RET
;
NORUBMSG:
	CALL	ILPRT
	DB	'Backspace is backspace',CR,LF,0
	RET
;
TOGLOC:
	MOV	AL,TOGGLELOC
	OR	AL,AL
	JNZ	TOGLOC1
	JMP	NOTVLD

TOGLOC1:
	NOT	LOCONEXTCHR
	CALL	TOGLOC2
	JMP	XPRT
;
TOGLOC2:
	CALL	ILPRT
	DB	'Use ',0
	MOV	AL,LOCONEXTCHR
	OR	AL,AL
	MOV	AL,EXTCHR
	JZ	LOCMSG
	CALL	SHFTYPE
	DB	' before local command',CR,LF,0
	RET
;
LOCMSG:
	CALL	SHFTYPE
	DB	' to send local command to remote',CR,LF,0
	RET
;
TOGLF:
	MOV	AL,TOGGLELF
	OR	AL,AL
	JNZ	TOGLF1
	JMP	NOTVLD

TOGLF1:
	NOT	ADDLF
	CALL	TOGLF2
	JMP	XPRT
;
TOGLF2:
	CALL	ILPRT
	DB	'Linefeed ',0
	MOV	AL,ADDLF
	OR	AL,AL
	JNZ	LFMSG
	CALL	ILPRT
	DB	'NOT ',0
LFMSG:
	CALL	ILPRT
	DB	'sent after <CR>',CR,LF,0
	RET
;
TOGSTL:
	MOV	AL,TOGSLF
	OR	AL,AL
	JNZ	TOGSTL1
	JMP	NOTVLD

TOGSTL1:
	NOT	STRLF
	CALL	TOGSTL2
	JMP	XPRT
;
TOGSTL2:
	CALL	ILPRT
	DB	'Linefeed ',0
	MOV	AL,STRLF
	OR	AL,AL
	JZ	SLFMSG
	CALL	ILPRT
	DB	'NOT ',0
SLFMSG:
	CALL	ILPRT
	DB	'sent after <CR> in terminal mode file output',CR,LF,0
	RET
;
TOGTXOFF:
	MOV	AL,TOGXOFF
	OR	AL,AL
	JNZ	TOGTXOFF1
	JMP	NOTVLD

TOGTXOFF1:
	CALL	ILPRT
	DB	'Use XOFF testing? (Y/N): ',0
	CALL	GETANS
	JC	NOCHG3
	MOV	XOFFTST,AL
NOCHG3:
	CALL	XOFFMSG
	MOV	AL,XOFFTST
	OR	AL,AL
	JNZ	NOCHG3A
	JMP	XPRT

NOCHG3A:
	NOT	AL
	MOV	XONWAIT,AL
	MOV	ECHWAIT,AL
	CALL	THEREF
	CALL	XONMSG
	CALL	ECHMSG
	JMP	XPRT
;
TOGTXON:
	CALL	ILPRT
	DB	'Use XON waiting after <CR> (Y/N): ',0
	CALL	GETANS
	JC	NOCHG4
	MOV	XONWAIT,AL
NOCHG4:
	CALL	XONMSG
	MOV	AL,XONWAIT
	OR	AL,AL
	JNZ	NOCHG4A
	JMP	XPRT

NOCHG4A:
	NOT	AL
	MOV	XOFFTST,AL		;DON'T ALLOW BOTH
	MOV	ECHWAIT,AL
	CALL	THEREF
	CALL	XOFFMSG
	CALL	ECHMSG
	JMP	XPRT
;
TOGWECH:
	CALL	ILPRT
	DB	'Use echo waiting before transmitting next character (Y/N): ',0
	CALL	GETANS
	JC	NOCHG5
	MOV	ECHWAIT,AL
NOCHG5:
	CALL	ECHMSG
	MOV	AL,ECHWAIT
	OR	AL,AL
	JNZ	NOCHG5A
	JMP	XPRT

NOCHG5A:
	NOT	AL
	MOV	XOFFTST,AL
	MOV	XONWAIT,AL
	CALL	THEREF
	CALL	XOFFMSG
	CALL	XONMSG
	JMP	XPRT
;
ECHMSG:	CALL	ILPRT
	DB	'Waiting for character echo ',0
	MOV	AL,ECHWAIT
	OR	AL,AL
	JNZ	ECHMSG2
	CALL	ILPRT
	DB	'NOT ',0
ECHMSG2:
	CALL	ILPRT
	DB	'used in terminal mode file output',CR,LF,0
	RET
;
GETANS:
	MOV	DX,OFFSET CMDBUF
	CALL	INBUFF
	MOV	AL,CMDBUF+2 	;GET ANSWER
	CMP	AL,' '
	CMC
	JZ	GETANSRT
	MOV	CH,AL
	CMP	AL,'N'
	MOV	AL,FALSE
	JZ	GETANSRT
	MOV	AL,CH
	CMP	AL,'Y'
	MOV	AL,TRUE
	JZ	GETANSRT
	POP	AX		;PRESERVE STACK
	JMP	NOTVLD
GETANSRT:
	RET
;
THEREF:
	CALL	ILPRT
	DB	'Therefore -',CR,LF,0
	RET
;
XOFFMSG:
	CALL	ILPRT
	DB	'XOFF testing ',0
	MOV	AL,XOFFTST
	OR	AL,AL
	JNZ	XOTSTON
	CALL	ILPRT
	DB	'NOT ',0
XOTSTON:
	CALL	ILPRT
	DB	'used',0
XONMSG3:
	CALL	ILPRT
	DB	' in terminal mode file output',CR,LF,0
	RET
;
XONMSG:
	CALL	ILPRT
	DB	'XON ',0
	MOV	AL,XONWAIT
	OR	AL,AL
	JNZ	XONMSG2
	CALL	ILPRT
	DB	'NOT ',0
XONMSG2:
	CALL	ILPRT
	DB	'automatically tested after <CR>',0
	JMP	XONMSG3
;
SETUPENT:
	MOV	AL,SETUPTST
	OR	AL,AL
	JNZ	SETUPENT1
	JMP	NOTVLD
SETUPENT1:
	CALL	SETUPR
	JMP	XPRT
;
NEWFILE:
	MOV	AL,NFILFLG
	OR	AL,AL
	JNZ	NOFILOPN	
	MOV	AL,FCB3+1	;CHECK THAT FILE WAS REQUESTED
	CMP	AL,' '
	JZ	NOFILOPN	;IF NO FILE, DON'T ERASE
	MOV	DX,OFFSET FCB3
	MOV	CL,ERASE
	CALL	BDOSRT
	MOV	AL,TRUE		;DO NOT ALLOW TERMINAL..
	MOV	NFILFLG,AL	;..SAVE SINCE NO FILE..
	NOT	AL		;..SPECIFIED.
	MOV	SAVEFLG,AL
	MOV	BX,OFFSET FCB3
	CALL	INITFCBS
	MOV	BX,OFFSET BOTTRAM
	MOV	HLSAVE,BX
	JMP	XPRT
;
WRTFIL:
	CMP	NFILFLG,TRUE
	JZ	NOFILOPN
	MOV	AL,FCB3+1	;CHECK THAT FILE WAS REQUESTED
	CMP	AL,' '
	JZ	NOFILOPN
	MOV	BX,HLSAVE
	CALL	NUMRECS		;DISK WRITE ROUTINE AS USED IN..
	CALL	WRTDSK		;..IN THE INTDSKSV ROUTINE.
	CALL	CLOSE3
	MOV	NFILFLG,TRUE
	MOV	SAVEFLG,FALSE
	MOV	BX,OFFSET FCB3
	CALL	INITFCBS	 ;BLANK OUT FCB SO WRITTEN FILE CAN'T BE ERASED
	MOV	BX,OFFSET BOTTRAM
	MOV	HLSAVE,BX
	JMP	XPRT
;
NOFILOPN:
	CALL	ILPRT
	DB	'++ No File Open ++',CR,LF,BELL,0
	JMP	XPRT
;
COMPARE:
	MOV	CH,BYTE PTR [BX]	;COMPARES A-REG WITH LIST..
COMPLP:
	INC	BX		;..ADDRESSED BY HL. FIRST ELEMENT..
	CMP	AL,BYTE PTR [BX]	;..OF LIST MUST BE NUMBER OF ELEMENTS..
	JZ	VALID		;..BEING COMPARED. RETURNS WITH..
	DEC	CH		;..CARRY SET IF A-REG DOES NOT..
	JNZ	COMPLP		;.. CONTAIN AN ELEMENT IN LIST.
	STC
VALID:
	RET
;
NXTSCRN:
	CALL    ILPRT
	DB	'HIT any KEY to CONTINUE',0
NOKEY1:
	CALL	STAT		;GET KEYBOARD STATUS
	JZ	NOKEY1		;KEEP LOOPING UNTIL KEYPRESS
	CALL	KEYIN		;GOBBLE UP KEYPRESS
	CALL	CLRTST
	RET
;
CLRTST:
	TEST	SCRNTEST,0FFH
	JZ	LOTSALF
	CALL	CLRSCRN
	RET
;
LOTSALF:
	MOV	AL,CR
	CALL	TIPE
	MOV	CH,12
	MOV	AL,LF
LFLOOP:
	CALL	TIPE
	DEC	CH
	JNZ	LFLOOP
	RET	
;
CURPAR:
	CALL	CLRTST
	CALL	ILPRT
	DB	'                Current Settings',CR,LF,LF,LF,0
	MOV	AL,CKSUMDFLT
	CALL	TOGCRC2
	MOV	AL,LSTTST
	OR	AL,AL
	JZ	NOLST3
	CALL	LSTMSG
NOLST3:
	CALL	DETCAR
	CALL	SETTIM2
	CALL	TOGBKSP2
	CALL	TOGLF2
	CALL	TOGLOC2
	CALL	ILPRT
	DB	'Terminal mode file buffer is ',0
	TEST	NFILFLG,0FFH
	JZ	ACTIVE
	CALL	ILPRT
	DB	'in',0
ACTIVE:
	CALL	ILPRT
	DB	'active',CR,LF,'Unused portion of buffer is ',0
	CALL	GETSPC
	CALL	ILPRT
	DB	' bytes',CR,LF,0
	TEST	SETUPTST,0FFH
	JZ	NOSETP
	CALL	GIVEPRM
NOSETP:
	CALL	TOGSTL2
	CALL	TOGTEOF2
	CALL	XOFFMSG
	CALL	XONMSG
	CALL	ECHMSG
	CALL	SPDMSG
	CALL	CRDLYMSG
	CALL	CRLF
	JMP	XPRT
;
GETSPC:
	CALL	GETMAX
	MOV	CH,AL
	MOV	BX,HLSAVE
	STC
	CMC
	MOV	AL,0
	SBB	AL,BL
	MOV	BL,AL
	MOV	AL,CH
	SBB	AL,BH
	MOV	BH,AL
	CALL	DECOUT
	RET
;
TFOMENU:
	CALL	CLRTST
	CALL	ILPRT
	DB	'     Commands for Setting Terminal Mode File Output'
	DB	' Parameters',CR,LF,LF,LF
	DB	'SPD - Set speed of file output',CR,LF
	DB	'TEF - Toggle transmission of end-of-file character',CR,LF,0
	MOV	AL,TOGSLF
	OR	AL,AL
	JZ	NOTOGSLF
	CALL	ILPRT
	DB	'TSL - Toggle stripping linefeeds',CR,LF
	DB	'TWE - Toggle wait for character echo',CR,LF,0
;
NOTOGSLF:
	TEST	TOGXOFF,0FFH
	JZ	NOTOGXOFF
	CALL	ILPRT
	DB	'TXF - Toggle XOFF testing',CR,LF
	DB	'TXN - Toggle XON waiting after <CR>',CR,LF,LF,LF,0
;
NOTOGXOFF:
	JMP	XPRT
;	
TOGTEOF:
	NOT	EOFSEND
	CALL	TOGTEOF2
	JMP	XPRT
;
TOGTEOF2:
	CALL	ILPRT
	DB	'End-of-file character ',0
	TEST	EOFSEND,0FFH
	JNZ	EOFMSG
	CALL	ILPRT
	DB	'NOT ',0
EOFMSG:
	CALL	ILPRT
	DB	'sent in terminal mode file output',CR,LF,0
	RET
;
;
;THIS ROUTINE DISPLAYS THE PHONE NUMBERS IN THE LIBRARY
;
NUMPRN:
	PUSH	BX
	CALL	CLRTST
	CALL	ILPRT
	DB	'           Library of Phone Numbers of Remote Systems',0
	MOV	CL,13       ;NUMBER OF LINES TO MOVE
	MOV	BX,OFFSET NUMBLIB  ;ADDRESS OF SOURCE MEMORY
	MOV	DX,OFFSET DBUF     ;ADDRESS OF TARGET MEMORY
	CALL	NEWLINE    ;START WITH CRLF
	XCHG	BX,DX
	MOV	BYTE PTR [BX],AL	;+LF
	XCHG	BX,DX
	INC	DX          ;AND BUMP IT
NUMPRN1:
	INC	BX		;SKIP PMMI DIALING LETTER
	INC	BX		;AND EQUAL SIGN
	MOV	CH,30		;NUMBER OF BYTES TO MOVE
	CALL	MOVE		;MOVE TO BUFFER
	CALL	SPACES		;2 ENTRIES + 3 SPACES = 63 CHARACTERS
	INC	BX
	INC	BX
	MOV	CH,30
	CALL	MOVE
	CALL	NEWLINE
	DEC	CL		;NUMBER OF LINES TO PRINT
	JZ	NUMPRN2
	JMP	NUMPRN1
;
NEWLINE:			;PUTS CR-LF AT MEMORY POINTED BY 'DE'
	MOV	AL,CR		;CR
	XCHG	BX,DX
	MOV	BYTE PTR [BX],AL
	MOV	AL,LF		;LF
	INC	BX		;BUMP POINTER
	MOV	BYTE PTR [BX],AL	;STORE LF
	XCHG	BX,DX
	INC	DX		;BUMP POINTER
	RET
;
SPACES:
	MOV	AL,20H	;SPACE
	XCHG	BX,DX
	MOV	BYTE PTR [BX],AL	;1
	INC	BX
	MOV	BYTE PTR [BX],AL	;2
	INC	BX
	MOV	BYTE PTR [BX],AL	;3
	INC	BX
	XCHG	BX,DX
	RET
;
NUMPRN2:
	MOV	AL,'$'
	XCHG	BX,DX
	MOV	BYTE PTR [BX],AL
	XCHG	BX,DX
	MOV	CL,PRINT
	MOV	DX,OFFSET DBUF	;POINT TO TABLE OF NUMBERS TO PRINT
	INT	224
	CALL	CRLF
	CALL	CRLF
	POP	BX
	JMP	XPRT
;
